# -*- coding: utf-8 -*-
import time
import sys
from PyQt4.QtGui import QWidget,QPainter,QPen,QFont
from PyQt4.QtCore import QEvent, QSize,Qt,pyqtSignal
from eventEngine import *

class VGDataMonitorForm(QWidget):
    """用于显示市场行情"""
    signal = pyqtSignal(type(Event()))
    """窗口关闭时触发"""
    closed = pyqtSignal()
    """还原时触发"""
    normaled = pyqtSignal()
    gridWidth = 0
    gridHeight = 0
    # ----------------------------------------------------------------------
    def __init__(self,eventEngine, parent=None):
        """Constructor"""
        super(VGDataMonitorForm, self).__init__(parent)
        self.__eventEngine = eventEngine
        self.parent = parent
        # 度量尺对象

        self.setWindowTitle(u'市场报价')
        """
        self.metrics = self.paint.fontMetrics()
        self.setAutoFillBackground(True)
        palette = self.palette()
        palette.setColor(self.backgroundRole(), Qt.black)
        self.setPalette(palette)
        self.dictData = {}
        self.pens = dict()
        self.pens['default'] = QPen(Qt.red, 1, Qt.SolidLine)
        self.pens['whiteDashLine'] = QPen(Qt.white, 1, Qt.DashLine)
        self.pens['whiteDashLine'].setDashPattern([4, 2])
        self.fonts = dict()
        self.fonts['default'] = QFont('Serif', 9, QFont.Light)
        """
        self.initUi()
        self.registerEvent()

    #设置当前字体
    def setFont(self, code='default'):
        self.paint.setFont(self.fonts[code])

    #设置当前笔刷
    def setPen(self, code='default'):
        self.paint.setPen(self.pens[code])

    def sizeHint(self):
        return QSize(500 ,300)



    def drawGrid(self):
        grid_num = 16
        cnt = self.gridHeight/ 10
        for i in range(0, grid_num):
            self.setPen('whiteDashLine')
            # 计算坐标
            y1 =  i * cnt
            x1 = 0
            x2 = self.gridWidth
            self.paint.drawLine(x1, y1, x2, y1)  # 画价位虚线


    def initUi(self):
          pass

    #关时发送信号
    def closeEvent(self, event):
        self.closed.emit()

    def changeEvent(self, event):
        print (self.windowState())
        if event.type() == QEvent.WindowStateChange and self.windowState() ==  Qt.WindowNoState:
            self.normaled.emit()

    def registerEvent(self):
       pass


    def updateData(self, event):
        pass
